<!--
/* 软件许可模块
 * Author:      cn2008tv 
 * CreateTime:  2023/10/12 18:58:52 
 * LastEditor:  cn2008tv 
 * ModifyTime:  2022/12/5 17:48:04 
 * Description: 
*/ 
-->
<template>
  <div class="jeecg-basic-table-form-container">
    <!--查询区域-->
    <div>
      <a-form @keyup.enter.native="searchQuery" :model="queryParam" :label-col="labelCol" :wrapper-col="wrapperCol">
        <a-row :gutter="24">

          <a-col :xl="4" :lg="5" :md="6" :sm="24">
            <a-form-item label="软件名称">
              <a-input placeholder="请输入软件名称" allowClear v-model:value="queryParam['*softwarename*']"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="4" :lg="5" :md="6" :sm="24">
            <a-form-item label="是否显示" >
              <a-select v-model:value="queryParam['isshow']" allowClear>
                <a-select-option value="1">显示</a-select-option>
                <a-select-option value="0">隐藏</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>

          <a-col :xl="5" :lg="5" :md="6" :sm="24">
            <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
              <a-col :lg="6">
                <a-button type="primary" preIcon="ant-design:search-outlined" @click="searchQuery">查询</a-button>
                <a-button type="primary" preIcon="ant-design:reload-outlined" @click="searchReset" style="margin-left: 8px">重置</a-button>
                <!-- <a @click="toggleSearchStatus = !toggleSearchStatus" style="margin-left: 8px">
                  {{ toggleSearchStatus ? '收起' : '展开' }}
                  <Icon :icon="toggleSearchStatus ? 'ant-design:up-outlined' : 'ant-design:down-outlined'" />
                </a> -->
              </a-col>
            </span>
          </a-col>

        </a-row>
      </a-form>
    </div>
    <!--引用表格-->
    <BasicTable @register="registerTable" :rowSelection="rowSelection">
      <!--插槽:table标题-->
      <template #tableTitle>
        <!-- <a-button type="primary" @click="handleAdd" preIcon="ant-design:plus-outlined"> 新增</a-button> -->
        <a-button type="primary" v-if="selectedRowKeys.length > 0" @click="handleSetShow" preIcon="ant-design:plus-outlined"> 显示</a-button>
        <a-button type="primary" v-if="selectedRowKeys.length > 0" @click="handleSetHide" preIcon="ant-design:plus-outlined"> 隐藏</a-button>
        <a-button  type="primary" preIcon="ant-design:export-outlined" @click="onExportXls"> 导出</a-button>
        <!-- <j-upload-button  type="primary" preIcon="ant-design:import-outlined" @click="onImportXls">导入</j-upload-button>
        <a-dropdown v-if="selectedRowKeys.length > 0">
          <template #overlay>
            <a-menu>
              <a-menu-item key="1" @click="batchHandleDelete">
                <Icon icon="ant-design:delete-outlined"></Icon>
                删除
              </a-menu-item>
            </a-menu>
          </template>
          <a-button>批量操作
            <Icon icon="mdi:chevron-down"></Icon>
          </a-button>
        </a-dropdown> -->
      </template>
      <!--操作栏-->
      <template #action="{ record }">
        <TableAction :actions="getTableAction(record)" :dropDownActions="getDropDownAction(record)"/>
      </template>
      <!--字段回显插槽-->
      <template #htmlSlot="{text}">
        <div v-html="text"></div>
      </template>
      <!--省市区字段回显插槽-->
      <template #pcaSlot="{text}">
        {{ getAreaTextByCode(text) }}
      </template>
      <template #fileSlot="{text}">
        <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
        <a-button v-else :ghost="true" type="primary" preIcon="ant-design:download-outlined" size="small" @click="downloadFile(text)">下载</a-button>
      </template>
    </BasicTable>
    <!-- 表单区域 -->
    <LicenseSoftwareModal ref="registerModal" @success="handleSuccess"></LicenseSoftwareModal>

    <SimplePopup
      v-if="disabled"
      code="license_contract_new"
      type="radio"
      :fieldConfig="[
		            { source: 'id', target: 'id' }
		          ]"
      :dataId="dataId"
      :closeDialog="closeDialog"
      :disabled="disabled"/>


  </div>
</template>

<script lang="ts" name="j_monitoring-licenseSoftware" setup>
  import { ref, reactive } from 'vue';
  import { BasicTable, useTable, TableAction } from '/@/components/Table';
  import { useListPage } from '/@/hooks/system/useListPage';
  import { columns } from './LicenseSoftware.data';
  import { list, deleteOne, batchDelete,batchShow,batchHide,saveOrUpdate, getImportUrl, getExportUrl } from './LicenseSoftware.api';
  import { downloadFile } from '/@/utils/common/renderUtils';
  import LicenseSoftwareModal from './components/LicenseSoftwareModal.vue'
  import {defHttp} from "/@/utils/http/axios";
  import {preprocessObj} from "/@/utils/common/compUtils";
  import SimplePopup from './components/SimplePopup.vue';
  import {useMessage} from '/@/hooks/web/useMessage';

  /**
   * 模块查询参数
   * 
   * */
  const queryParam = ref<any>({
    isDeleted:'0'
  });
  const toggleSearchStatus = ref<boolean>(false);
  const registerModal = ref();
  const settingOptions = [
    { label: '显示', value: 1 },
    { label: '隐藏', value: 0 },
  ];
  //注册table数据
  const { prefixCls, tableContext, onExportXls, onImportXls } = useListPage({
    tableProps: {
      title: '软件列表',
      api: list,
      tableSetting:{
        cacheKey:'软件列表'
      },
      columns,
      canResize:false,
      useSearchForm: false,
      actionColumn: {
        width: 240,
        fixed: 'right',
      },
      defSort: {
        column: 'sortNo',
        order: 'asc',
      },
      beforeFetch: (params) => {
        let val = preprocessObj(queryParam.value);

        return Object.assign(params, val);
      },
    },
    exportConfig: {
      name: "软件列表",
      url: getExportUrl,
    },
	  importConfig: {
	    url: getImportUrl,
	    success: handleSuccess
	  },
  });
  const { createErrorModal } = useMessage();
  const [registerTable, { reload, collapseAll, updateTableDataRecord, findTableDataRecord, getDataSource }, { rowSelection, selectedRowKeys }] = tableContext;
  //标签响应设置
  const labelCol = reactive({
    xs: { span: 24 },
    sm: { span: 7 },
  });
//输入框响应设置
  const wrapperCol = reactive({
    xs: { span: 24 },
    sm: { span: 16 },
  });

  /**
   * 新增事件
   */
  function handleAdd() {
    registerModal.value.disableSubmit = false;
    registerModal.value.add();
  }

  /**
   * 编辑事件
   */
  function handleEdit(record: Recordable) {
    registerModal.value.disableSubmit = false;
    registerModal.value.edit(record);
  }

  /**
   * 详情
   */
  function handleDetail(record: Recordable) {
    registerModal.value.disableSubmit = true;
    registerModal.value.edit(record);
  }

  /**
   * 删除事件
   */
  async function handleDelete(record) {
    await deleteOne({ id: record.id }, handleSuccess);
  }

  /**
   * 批量删除事件
   */
  async function batchHandleDelete() {
    await batchDelete({ ids: selectedRowKeys.value }, handleSuccess);
  }

  /**
   * 批量显示事件
   */
  async function handleSetShow() {
    await batchShow({ ids: selectedRowKeys.value }, handleSuccess);
  }
  
  /**
   * 批量隐藏事件
   */
   async function handleSetHide() {
    await batchHide({ ids: selectedRowKeys.value }, handleSuccess);
  }
  /**
   * 成功回调
   */
  function handleSuccess() {
    (selectedRowKeys.value = []) && reload();
  }

  /**
   * 操作栏
   */
  function getTableAction(record) {
    return [
        {
          label: '展示',
          onClick: setShow.bind(null,record,!record.isshow),
        },
        {
          label: '编辑',
          onClick: handleEdit.bind(null,record),          
        },
        {
          label: '模块管理',
          onClick: moduleShow.bind(null,record),
        }
      ];
  }

  /**
   * 下拉操作栏
   */
  function getDropDownAction(record) {
    return [
      // {
      //   label: '详情',
      //   onClick: handleDetail.bind(null, record),
      // }, {
      //   label: '删除',
      //   popConfirm: {
      //     title: '是否确认删除',
      //     confirm: handleDelete.bind(null, record),
      //   }
      // }
    ]
  }

  /**
   * 查询
   */
  function searchQuery() {
    reload();
  }

  /**
   * 重置
   */
  function searchReset() {
    queryParam.value = {};
    selectedRowKeys.value = [];
    //刷新数据
    reload();
  }

  async function setShow(record , show){
    if(show){
      record.isshow = 1;
    }
    else{
      record.isshow = 0;
    }
    saveOrUpdate(record, true).catch((e)=>{
      createErrorModal({
            title: "设置失败",
            content: e,
          });
    }).finally(()=>{
      handleSuccess();
    });
  }    


  const disabled = ref(false)
  /**
   * 是否不可用
   * */
  const dataId = ref('')

  function moduleShow(record){
    dataId.value = record.id
    console.log(dataId.value)
    disabled.value = true
  }

  /**
   * 关闭对话框
   * 
   * */
  function closeDialog() {
    disabled.value = false;
  }




</script>

<style lang="less" src="/@/assets/style/TableToolbar.less" scoped></style>
